package hyl.base.net.iot;

import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import hyl.core.MyCharset;
import hyl.core.MyFun;
import hyl.core.conf.MyConst;
/**
 * 主配置程序类
 * @author 37798955@qq.com
 *
 */
public class Conf {

	public static MyConst const1;
	public static Charset D编码;
	public static Charset BA编码;
	public static Charset HTTP编码;
	public static String HTTP_IP ;
	public static int HTTP_PORT ;
	public static int HTTPS_PORT;
	public static String CONTEXT;
	// HEART_C 必须小于TIMEOUT_C
	public static int HEART_C_MS=60000 ; // 60s 心跳间隔时间
	public static int TIMEOUT_C_MS =120000; // 120s iC端连接超时(毫秒)	
	public static int TIMEOUT_C_S=120 ; // 120s iC端连接超时(毫秒)	
	public static InetSocketAddress inetSocketA=null;//上级服务的ip地址
	public static InetSocketAddress inetSocketB=null;//当前服务的ip地址
	public static Conf me;
	public static String A_Servname;
	public static String B_Servname;
	static {
		Conf.getInstance();		
	}
	public Conf() {
		const1 = MyConst.getInstance();	
		D编码 = MyCharset.forname(Conf.const1.get("BC_CHARSET"), MyCharset._ASCII);
		BA编码 =MyCharset.forname( Conf.const1.get("AB_CHARSET"), MyCharset._UTF8);
		HTTP编码 =MyCharset.forname( Conf.const1.get("A_CHARSET"), MyCharset._UTF8);
		HTTP_IP =MyFun.nvlStr( Conf.const1.get("HTTP_IP"),"0.0.0.0");
		HTTP_PORT = MyFun.str2int(Conf.const1.get("HTTP_PORT"),0);
		HTTPS_PORT = MyFun.str2int(Conf.const1.get("HTTPS_PORT"),0);
		CONTEXT = MyFun.nvlStr(Conf.const1.get("CONTEXT"),"/");
		String ipa = MyFun.nvlStr(Conf.const1.get("IP_A"),"0.0.0.0");
		int porta = MyFun.str2int(Conf.const1.get("PORT_A"),0);
		String ipb =MyFun.nvlStr( Conf.const1.get("IP_B"),"0.0.0.0");
		int portb = MyFun.str2int(Conf.const1.get("PORT_B"),11998);
		if (porta>0)
			inetSocketA = new InetSocketAddress(ipa, porta);
		inetSocketB = new InetSocketAddress(ipb, portb);
		TIMEOUT_C_MS = MyFun.str2int(Conf.const1.get("TIMEOUT_C"),120000);
		TIMEOUT_C_S=TIMEOUT_C_MS/1000;
		HEART_C_MS = MyFun.str2int(Conf.const1.get("HEART_C"),TIMEOUT_C_MS/2);

		B_Servname= const1.get("B_SERVERNAME");
		A_Servname= const1.get("A_SERVERNAME");
	}

	public static Conf getInstance() {
		if (me == null)
			me = new Conf();
		return me;
	}

}
